<template>
	<view class="box-wp" v-if="list.length>0">
		<view class="item" v-for="(info,index) in list" :key="index">
			<view class="main">
				<view class="left">
					<u--image :src="info.image" width="160rpx" height="160rpx" mode="aspectFill"></u--image>
				</view>
				<view class="right flex-1">
					<view class="title u-line-2">
						{{info.name||""}}
					</view>
					<view class="gift-price">
						{{info.price?`￥${info.price}`:''}}
					</view>
					<view class="option-btn-wp">
						<view class="share-wp">
							共分享{{info.share?info.share:0}}次
						</view>
						<view class="option-btn" @click.stop="goToShareCoupon(info)">
							赠送
						</view>
						<view class="option-btn" @click.stop="delMyGifts(info)">
							作废
						</view>

					</view>
				</view>
			</view>

		</view>
	</view>
	<u-empty marginTop="50" mode="list" textSize="30" iconSize="70" v-else>
	</u-empty>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				pageNo: 1,
				total: 0,
				pageSize: 10,
			}
		},
		// created() {
		// 	this.getList(1)
		// },
		props: {
			openId: {
				required: true,
				type: String
			}
		},
		methods: {

			async getList(arg) {
				uni.showLoading({})
				if (arg == 1) {
					this.pageNo = 1
					this.list = []
					this.total = 0
				}
				let {
					openid
				} = uni.getStorageSync('openId')
				let res = await this.$api.getMsGiftPacksPage({
					openId: openid,
					pageNo: this.pageNo,
					pageSize: this.pageSize,
				})
				if (res.success) {

					console.log(res.result.records);
					this.list = [...this.list, ...res.result.records]
					this.total = res.result.total
				} else {
					this.list = []
					this.total = 0
				}
				uni.hideLoading()
			},
			goToShareCoupon(item) {
				uni.navigateTo({
					url: `/pagesMall/mallCenter/mallCenterGiftsDetail?id=${item.id}&hiddenBuyBtn=1&openId=${item.openId}`
				})
			},

			reachBottom() {
				if (this.pageNo * this.pageSize > this.total) {
					uni.showToast({
						title: '没有更多数据',
						icon: 'none'
					})
				} else {
					this.pageNo++
					this.getList()
				}
			},
			delMyGifts({
				id
			}) {
				let that = this
				uni.showModal({
					title: '提示',
					content: '是否作废该大礼包',
					success: async (modal) => {
						if (modal.confirm) {
							let res = await that.$api.delteMyGiftPacks(
								id
							)
							if (res.success) {
								that.getList(1)
							} else {
								uni.showToast({
									title: res.message,
									icon: 'none'
								})
							}
						}
					}
				});

			},
		}
	}
</script>

<style lang="scss" scoped>
	.box-wp {
		overflow: auto;
		background-color: #f7f8fa;
		min-height: 100vh;

		.item {
			border-radius: 16rpx;
			background-color: #fff;
			margin: 32rpx;
			padding: 20rpx;

			.main {
				display: flex;
				justify-content: space-between;

				.left {
					margin-top: 5rpx;
					margin-right: 32rpx;

					image {
						border-radius: 5rpx;
						width: 140rpx;
						height: 140rpx;
					}
				}

				.right {
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.title {
						width: 450rpx;
						height: 80rpx;
						font-size: 28rpx;
						font-weight: 600;
						color: #1D2129;
					}

					.goods {
						margin-top: 16rpx;
						width: 454rpx;
						height: 34rpx;
						font-size: 24rpx;
						color: #86909C;
						line-height: 34rpx;
					}

					.gift-price {
						height: 40rpx;
						color: #FF3131;
						font-size: 30rpx;
					}

					.option-btn-wp {
						display: flex;
						justify-content: space-between;
						align-items: flex-end;

						.share-wp {
							width: 142rpx;
							height: 48rpx;
							font-size: 24rpx;
							font-weight: 400;
							color: #C9CDD4;
							line-height: 48rpx;
						}


						.option-btn {
							text-align: center;
							width: 112rpx;
							height: 48rpx;
							border-radius: 200rpx 200rpx 200rpx 200rpx;
							border: 2rpx solid #86909C;
							font-size: 24rpx;
							font-weight: 400;
							color: #86909C;
							line-height: 48rpx;


						}


					}




				}
			}

			.bottom {
				.sell-box {
					margin-top: 24rpx;

					.sell-box-name {
						height: 40rpx;
						font-size: 28rpx;
						font-weight: 400;
						color: #4E5969;
						line-height: 39rpx;
					}

					.sell-box-name2 {
						height: 40rpx;
						font-size: 28rpx;
						font-weight: 600;
						color: #1D2129;
						line-height: 39rpx;
					}
				}

				.time-box {
					margin-top: 24rpx;

					.time {
						height: 40rpx;
						font-size: 28rpx;
						font-weight: 400;
						color: #86909C;
						line-height: 39rpx;
					}

					.detail {
						height: 40rpx;
						font-size: 28rpx;
						font-weight: 400;
						color: #276AEE;
						line-height: 39rpx;
					}
				}

			}




		}

	}
</style>